﻿using HardcoreGame.Content.Items.Placeable.Banners;
using Terraria;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;

namespace HardcoreGame.Content.NPCs.Enemies.Biomesa.Underground
{
	public class StoneGolem : ModNPC
	{
		public override void SetStaticDefaults()
		{
			Main.npcFrameCount[NPC.type] = Main.npcFrameCount[482];
		}
        public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
        {
            bestiaryEntry.Info.AddRange([
                BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Caverns,
                new FlavorTextBestiaryInfoElement("Mods.HardcoreGame.Bestiary.StoneGolem")
            ]);
        }
        public override void SetDefaults()
		{
            NPC.CloneDefaults(482);
            NPC.width = 48;
            NPC.height = 56;
            NPC.damage = 80;
            NPC.defense = 108;
            NPC.lifeMax = 2700;
            NPC.knockBackResist = 0.8f;
            NPC.HitSound = SoundID.NPCHit41;
            NPC.DeathSound = SoundID.NPCDeath44;
            NPC.value = 150f;
            NPC.aiStyle = 3;
            AIType = 482;
            AnimationType = 482;
            Banner = NPC.type;
            BannerItem = ModContent.ItemType<StoneGolemBanner>();
		}
		public override float SpawnChance(NPCSpawnInfo spawnInfo)
		{
			if (spawnInfo.Player.ZoneRockLayerHeight && !spawnInfo.Player.ZoneJungle && !spawnInfo.Player.ZoneCorrupt && !spawnInfo.Player.ZoneCrimson && !spawnInfo.Player.ZoneHallow && !spawnInfo.Player.ZoneSnow && !spawnInfo.Player.ZoneDesert && !spawnInfo.Player.ZoneTowerStardust && !spawnInfo.Player.ZoneTowerVortex && !spawnInfo.Player.ZoneTowerNebula && !spawnInfo.Player.ZoneTowerSolar)
			{
				return 0.25f;
			}			
			return 0f;
		}
		public override void HitEffect(NPC.HitInfo hit)
		{
			for (int i = 0; i < 10; i++)
			{
				int dustType = 1;
				int dustIndex = Dust.NewDust(NPC.Center, NPC.width, NPC.height, dustType, 0f, 0f, 0, default, 1f);
				Dust dust = Main.dust[dustIndex];
				dust.velocity.X += Main.rand.Next(-50, 51) * 0.01f;
				dust.velocity.Y += Main.rand.Next(-50, 51) * 0.01f;
				dust.scale *= 1f + Main.rand.Next(-30, 31) * 0.01f;
			}
		}
	}
}
